package com.dxy.lc.listener;

import com.dxy.lc.listener.event.UserEditEvent;
import com.dxy.lc.manager.UserCacheManager;
import com.dxy.lc.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class UserEditEventListener implements ApplicationListener<UserEditEvent> {
    @Override
    public void onApplicationEvent(UserEditEvent userEditEvent) {
        List<Integer> userIds = userEditEvent.getUserId();
        log.debug("UserEditEventListener-userIds: {}", JsonUtil.toJSON(userIds));
        userIds.forEach(id -> UserCacheManager.INSTANCE.removeById(id));
    }
}
